`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    17:07:19 11/22/2013 
// Design Name: 
// Module Name:    ZerosLeft_lut 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module ZerosLeft_lut(
    Code,
    ZerosLeft,
    RunBefore,
	 CodeLength
    );
input [15:0] Code;
input [3:0] ZerosLeft;
output [3:0] RunBefore;
output [3:0] CodeLength;

reg [3:0] RunBefore;
reg [3:0] CodeLength;
wire [3:0] count;
zero_count zc_for_zerosLeft_lut (
    .Code(Code), 
    .count(count)
    );
always @(*) begin
	case(ZerosLeft)
	1:begin
		case(Code[0])
		1'b0:begin
			RunBefore = 1;
			CodeLength = 1;
		end
		1'b1:begin
			RunBefore = 0;
			CodeLength = 1;
		end
		endcase
	end
	2:begin
		case(Code[1:0])
		2'b00:begin
			RunBefore = 2;
			CodeLength = 2;
		end
		2'b01:begin
			RunBefore = 0;
			CodeLength = 1;
		end
		2'b10:begin
			RunBefore = 1;
			CodeLength = 2;
		end
		2'b11:begin
			RunBefore = 0;
			CodeLength = 1;
		end
		endcase
	end
	3:begin
		case(Code[1:0])
		2'b00:begin
			RunBefore = 3;
			CodeLength = 2;
		end
		2'b01:begin
			RunBefore = 1;
			CodeLength = 2;
		end
		2'b10:begin
			RunBefore = 2;
			CodeLength = 2;
		end
		2'b11:begin
			RunBefore = 0;
			CodeLength = 2;
		end
		endcase
	end
	4:begin
		case(Code[1:0])
		2'b00:begin
			case(Code[2])
			1'b0:begin
				RunBefore = 4;
				CodeLength = 3;
			end
			1'b1:begin
				RunBefore = 3;
				CodeLength = 3;
			end	
			endcase	
		end
		2'b01:begin
			RunBefore = 1;
			CodeLength = 2;
		end
		2'b10:begin
			RunBefore = 2;
			CodeLength = 2;
		end
		2'b11:begin
			RunBefore = 0;
			CodeLength = 2;
		end
		endcase
	end
	5:begin
		case(Code[1:0])
		2'b00:begin
			case(Code[2])
			1'b0:begin
				RunBefore = 5;
				CodeLength = 3;
			end
			1'b1:begin
				RunBefore = 4;
				CodeLength = 3;
			end
			endcase			
		end
		2'b01:begin
			RunBefore = 1;
			CodeLength = 2;
		end
		2'b10:begin
			case(Code[2])
			1'b0:begin
				RunBefore = 3;
				CodeLength = 3;
			end
			1'b1:begin
				RunBefore = 2;
				CodeLength = 3;
			end	
			endcase
		end
		2'b11:begin
			RunBefore = 0;
			CodeLength = 2;
		end
		endcase	
	end
	6:begin
		case(Code[2:0])
		3'b000:begin
			RunBefore = 1;
			CodeLength = 3;
		end
		3'b001:begin
			RunBefore = 6;
			CodeLength = 3;
		end
		3'b010:begin
			RunBefore = 4;
			CodeLength = 3;
		end
		3'b011:begin
			RunBefore = 0;
			CodeLength = 2;
		end
		3'b100:begin
			RunBefore = 2;
			CodeLength = 3;
		end
		3'b101:begin
			RunBefore = 5;
			CodeLength = 3;
		end
		3'b110:begin
			RunBefore = 3;
			CodeLength = 3;
		end
		3'b111:begin
			RunBefore = 0;
			CodeLength = 2;
		end
		endcase
	end
	default:begin
		case(count)
		0,1,2:begin
			case(Code[2:0])
			3'b000:begin
				RunBefore = 0;
				CodeLength = 3;
			end
			3'b001:begin
				RunBefore = 3;
				CodeLength = 3;
			end
			3'b010:begin
				RunBefore = 5;
				CodeLength = 3;
			end
			3'b011:begin
				RunBefore = 1;
				CodeLength = 3;
			end
			3'b100:begin
				RunBefore = 6;
				CodeLength = 3;
			end
			3'b101:begin
				RunBefore = 2;
				CodeLength = 3;
			end
			3'b110:begin
				RunBefore = 4;
				CodeLength = 3;
			end
			3'b111:begin
				RunBefore = 0;
				CodeLength = 3;
			end
			endcase
		end
		3,4,5,6,7,8,9,10:begin
			RunBefore = count+4;
			CodeLength = count+1;
		end
		default:begin
			RunBefore = 0;
			CodeLength = 0;
		end
		endcase
	end
	endcase
end

endmodule
